package itbour.onetouchshow.activity.challengezone;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;

import java.util.HashMap;

import itbour.onetouchshow.App;
import itbour.onetouchshow.base.mvp.BasePresenterImpl;
import itbour.onetouchshow.bean.FreeCreateOrigin;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;


public class ChallengeZonePresenter extends BasePresenterImpl<ChallengeZoneContract.View> implements ChallengeZoneContract.Presenter {
    public void onloadNet(FreeCreateOrigin freeCreateOrigin) {
        // JsonUtils.swapTransitions(freeCreateOrigin.getTransition());
        String docJson = new Gson().toJson(freeCreateOrigin);
        L_.e("ChallengeZonePresenter" + docJson);
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("docJson", docJson);
        HttpUtils.getInstance().executeGet(AppConfig.CUSTOMVIDEO, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                // T_.showToastReal(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(response);
                String videoUrl = jsonObject.getString("videoUrl");
                if (mvpView != null) {
                    mvpView.loadSucceed(videoUrl);
                }
                L_.e(videoUrl);
            }
        });

    }


    public void newCustomVideoDoc(FreeCreateOrigin freeCreateOrigin, int sizeId) {
        String docJson = new Gson().toJson(freeCreateOrigin);
        String userId = App.getUserId();
        L_.e("ChallengeZonePresenter" + docJson);
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("docString", docJson);
        stringStringHashMap.put("device", String.valueOf(AppConst.ANDROID_DEVICE));
        stringStringHashMap.put("userId", userId);
        stringStringHashMap.put("sizeId", sizeId + "");
        HttpUtils.getInstance().executeGet(AppConfig.NEWCUSTOMVIDEODOC_APP_V3_0, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                // T_.showToastReal(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                //T_.showToastReal(response);
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });

    }


    public void updataCustomVideoDoc(FreeCreateOrigin freeCreateOrigin, String docId) {
        String docJson = new Gson().toJson(freeCreateOrigin);
        String userId = App.getUserId();
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("docString", docJson);
        stringStringHashMap.put("device", String.valueOf(AppConst.ANDROID_DEVICE));
        stringStringHashMap.put("userId", userId);
        stringStringHashMap.put("docId", docId);
        HttpUtils.getInstance().executeGet(AppConfig.UPDATECUSTOMVIDEODOC, stringStringHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                T_.showToastReal(exception);
                if (mvpView != null) {
                    mvpView.loadFaild(exception);
                }
            }

            @Override
            protected void onSuccess(String response) {
                if (mvpView != null) {
                    mvpView.loadSucceed(response);
                }
            }
        });

    }
}
